package com.hzncc.flowable_diboot.controller.contract;

import com.diboot.core.vo.JsonResult;
import com.diboot.core.vo.Pagination;
import com.diboot.file.util.HttpHelper;
import com.hzncc.flowable_diboot.entity.contract.ContractProgress;
import com.hzncc.flowable_diboot.service.ContractProgressService;
import com.hzncc.flowable_diboot.vo.contract.ContractProgressListVO;
import jakarta.annotation.Nullable;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.File;
import java.util.List;

@RestController
@RequestMapping("/contract-progress")
public class ContractProgressController {

    @Autowired
    private ContractProgressService contractProgressService;


    @GetMapping()
    public JsonResult<?> getList(ContractProgress queryDto, Pagination pagination) {
        List<ContractProgressListVO> list = contractProgressService.getList(queryDto, pagination);
        return JsonResult.OK(list).bindPagination(pagination);
    }

    @GetMapping("/export")
    public JsonResult<?> export(ContractProgress queryDto,HttpServletResponse response) throws Exception {
        File file = contractProgressService.exportFile(queryDto);
        HttpHelper.downloadLocalFile(file, file.getName(), response);
        return null;
    }
}
